﻿Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient


''' <summary>
''' Clase de la capa de acceso a datos DAL que implementa el patrón Table Data Gateway para el manejo de la entidad Estado_Busqueda
''' </summary>
''' <remarks></remarks>
Public Class TDGEstado_Busqueda

    Private Shared m_Instance As TDGEstado_Busqueda = Nothing


    Public Function Insert(conn As SqlConnection, _
                           EstB_Codigo As String, _
                           EstB_Descrip As String, _
                           DVH As Int32) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.addEstado_Busqueda"
        command.Parameters.AddWithValue("@EstB_Codigo", EstB_Codigo)
        command.Parameters.AddWithValue("@EstB_Descrip", EstB_Descrip)
        command.Parameters.AddWithValue("@DVH", DVH)



        iRowsAffected = command.ExecuteNonQuery()


        Return iRowsAffected

    End Function

    Public Function Update(conn As SqlConnection, _
                           EstB_Codigo As String, _
                           EstB_Descrip As String, _
                           DVH As Int32) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.updEstado_Busqueda"
        command.Parameters.AddWithValue("@EstB_Codigo", EstB_Codigo)
        command.Parameters.AddWithValue("@EstB_Descrip", EstB_Descrip)
        command.Parameters.AddWithValue("@DVH", DVH)


        iRowsAffected = command.ExecuteNonQuery()

        Return iRowsAffected

    End Function

    Public Function Delete(conn As SqlConnection, EstB_Codigo As String) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16

        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "dbo.delEstado_Busqueda"
        command.Parameters.AddWithValue("@EstB_Codigo", EstB_Codigo)

        iRowsAffected = command.ExecuteNonQuery()

        Return iRowsAffected

    End Function

    Public Function Find(conn As SqlConnection, EstB_Codigo As String) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getEstado_Busqueda"
        command.Parameters.AddWithValue("@EstB_Codigo", EstB_Codigo)


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Function FindAll(conn As SqlConnection) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getEstado_Busqueda_ALL"


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Shared ReadOnly Property Instance()
        Get
            If (m_Instance Is Nothing) Then
                m_Instance = New TDGEstado_Busqueda()
            End If

            Return m_Instance
        End Get
    End Property

    Private Sub New()

    End Sub

End Class
